# -*- coding: utf-8 -*-
#   __author__ = "Casey"     Email = 395280963qq.com
#   Data :2019/11/11  Python:3.7

import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
import requests

class Login():
    """
    实现满集网自动登录
    """
    def check_pwd(self,pwd):
        """
        :param pwd:
        :return:
        """
        #   此处的公钥是在网站上抓取的
        key = """-----BEGIN PUBLIC KEY----- 
        MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC4wHerJc4BSst20Zb07lY9LeZss4OEEhe+SrnLyYy8hGquX/aTQNn+5wnV/+8ierKPgqPGIXPf1ZRww5/6yON+O7dAfJ7BRx85HneIWqwPCZToLck8DN8UXsBuXLMcG7tfMunnnZKenrPsAslN0eKvkYkvz4EPGdvmPwz0NCKXQIDAQAB
            -----END PUBLIC KEY-----"""   #   注意  公钥格式必须这样写！！！
        rsakey = RSA.importKey(key)
        cipher = Cipher_pkcs1_v1_5.new(rsakey)  # 生成对象
        cipher_text = base64.b64encode(cipher.encrypt(pwd.encode(encoding="utf-8")))  # 对传递进来的用户名或密码字符串加密
        value = cipher_text.decode('utf8')  # 将加密获取到的bytes类型密文解码成str类型
        return value

    def make_data(self,user,pwd):
        """
        制造参数
        :param user:
        :param pwd:
        :return data:
        """
        data = {
            'account': user,
            'password': self.check_pwd(pwd=pwd),
            'returnUrl':'/',
        }
        return data

    def main(self):
        url = 'http://www.manjiwang.com/Logins/BuyerLogin'
        dd = requests.post(url,data=self.make_data(user=user,pwd=pwd))
        data = dd.content.decode('utf-8')
        print(data)


if __name__ == '__main__':
    Lg = Login()
    user = input('请输入账户:')
    pwd = input('请输入密码:')
    Lg.main()
